<script setup lang="ts">
import LoginAccount from './login-account.vue'
import LoginPhone from './login-phone.vue'

// 1. 定义属性
const isKeepPassword = ref(true)
const accountRef = ref<InstanceType<typeof LoginAccount>>()
const phoneRef = ref<InstanceType<typeof LoginPhone>>()

enum TabType {
  Account = 'account', // 账号登陆
  Phone = 'phone' // 手机号码登录
}
const currentTab = ref<TabType>(TabType.Account)

// 2. 定义方法
const handleLoginBtnClick = () => {
  if (currentTab.value === TabType.Account) {
    accountRef.value?.loginAction(isKeepPassword.value)
  } else {
    phoneRef.value?.loginAction()
  }
}
</script>
<template>
  <div class="login-panel">
    <h1 class="title">后台管理系统</h1>

    <el-tabs v-model="currentTab" type="border-card" stretch>
      <el-tab-pane :name="TabType.Account">
        <template #label>
          <span class="custom-tabs-label">
            <el-icon><icon-ep-user-filled /></el-icon>
            <span>账号登录</span>
          </span>
        </template>
        <login-account ref="accountRef" />
      </el-tab-pane>
      <el-tab-pane :name="TabType.Phone">
        <template #label>
          <span class="custom-tabs-label">
            <el-icon><icon-ep-iphone /></el-icon>
            <span>手机登录</span>
          </span>
        </template>
        <login-phone ref="phoneRef" />
      </el-tab-pane>
    </el-tabs>

    <div class="account-control">
      <el-checkbox v-model="isKeepPassword">记住密码</el-checkbox>
      <el-link type="primary">忘记密码</el-link>
    </div>

    <el-button type="primary" class="login-btn" @click="handleLoginBtnClick">
      立即登录
    </el-button>
  </div>
</template>

<style lang="scss" scoped>
.login-panel {
  margin-bottom: 150px;
  width: 320px;
  .title {
    text-align: center;
  }
  .account-control {
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
  }
  .login-btn {
    margin-top: 10px;
    width: 100%;
  }
}
</style>
